<script setup>
import {tree as treeDept} from "@/apis/sys/dept.js";
import {ref} from "vue";
onMounted(() => {
  loadDeptTree()
})
const modelValue = defineModel('value')
const props = defineProps({
  disabled: {
    type: Boolean,
    default: false
  },
  keyField: {
    type: String,
    default: 'deptNo'
  },
  multiple: {
    type: Boolean,
    default: false
  }
})
const deptTree = ref([])
const loadDeptTree = async () => {
  const {code, data} = await treeDept()
  if (code === 0) {
    deptTree.value = data
  }
}
</script>

<template>
  <n-tree-select
      :options="deptTree"
      label-field="name"
      :key-field="props.keyField"
      clearable
      :multiple="props.multiple"
      v-model:value="modelValue"
      :disabled="props.disabled"/>
</template>

<style scoped>

</style>